#include<bits/stdc++.h>
using namespace std;
const int N = 20,mod = 1e9+7;
int n,k,a[N],b[N],v[N],c[N],sum,o,cnt;
inline int ksm(int x,int p)
{
	int ans = 1;
	while(p)
	{
		if((p&1)) ans = ans*x%mod;
		x = x*x%mod;
		p>>=1;
	}
	return ans;
}
inline void dfs(int x)
{
	if(x == k+1)
	{
		for(int i = 1;i <= n;i++) c[i] = a[i];
		o = n;
		for(int i = 1;i <= k;i++)
		{
			if(b[i] >= o) return;
			c[b[i]] -= c[b[i]+1];
			for(int j = b[i]+1;j < o;j++) c[j] = c[j+1];
			o--;
		}
		for(int i = 1;i <= n-k;i++) cnt+=c[i];
		sum++;
		return;
	}
	for(int i = 1;i <= n;i++)
		b[x] = i,dfs(x+1);
}
signed main()
{
  freopen("game1.in","r",stdin);
//  freopen("game.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for(int i = 1;i <= n;i++) cin >> a[i];
	dfs(1);
	cout<<cnt;
    return 0;
}
